package com.bulletelc.apollopre.module.display.product.details.detail;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.constants.NetWorkPath;
import com.bulletelc.apollopre.framework.BaseFragment;

/**
 * Created by Administrator on 2018/4/30.
 */

public class ProductDetailFragment extends BaseFragment {

    private WebView wvDetail;
    private boolean first = true;

    @Override
    public int getLayoutRes() {
        return R.layout.product_detail_fragment;
    }

    @Override
    public void assignViews() {
        wvDetail = findView(R.id.wvDetail);
    }

    @Override
    public void setListener() {

    }

    @Override
    public void initData(Bundle savedInstanceState) {
        initWebView();
    }

    /**
     * 初始化WebView
     */
    private void initWebView() {
        WebSettings settings = wvDetail.getSettings();
        settings.setJavaScriptEnabled(true);//支持js

        //缩放操作
        //settings.setDisplayZoomControls(false); //隐藏原生的缩放控件
        //settings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false，则该WebView不可缩放
        //settings.setSupportZoom(true); //支持缩放，默认为true。是下面那个的前提。

        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);//不缓存
        //settings.setDefaultTextEncodingName("utf-8");//设置编码格式
        //settings.setUseWideViewPort(true);
        // settings.setLoadWithOverviewMode(true);
        //支持插件

        //设置自适应屏幕，两者合用
        //settings.setUseWideViewPort(true); //将图片调整到适合webview的大小
        //settings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小


        //        webView.setWebChromeClient(new WebChromeClient(){
        //            @Override
        //            public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
        //                LogUtil.i(message);
        //                return super.onJsAlert(view, url, message, result);
        //
        //            }
        //        });

        wvDetail.setWebViewClient(new WebViewClient());
    }

    public void update(String id) {
        //加载WebView
        if (first) {
            wvDetail.loadUrl(NetWorkPath.WEB_VIEW_PRODUCT_DETAIL + "?id=" + id);
            first = false;
        }
    }
}
